import request from "@/utils/request";
import { AxiosPromise } from "axios";
import { ProPageResult, ProQuery, ProForm } from "./type";

/**
 * 获取商品分页数据
 *
 * @param queryParams
 */
export function getProPage(
  queryParams?: ProQuery
): AxiosPromise<ProPageResult> {
  return request({
    url: "/api/business/products/page",
    method: "get",
    params: queryParams,
  });
}

/**
 * 获取商品
 *
 * @param id
 */
export function getProForm(id: number): AxiosPromise<ProForm> {
  return request({
    url: "/api/business/products/" + id + "/form",
    method: "get",
  });
}

/**
 * 添加商品
 *
 * @param data
 */
export function addPro(data: ProForm) {
  return request({
    url: "/api/business/products",
    method: "post",
    data: data,
  });
}

/**
 * 更新商品
 *
 * @param id
 * @param data
 */
export function updatePro(id: string, data: ProForm) {
  return request({
    url: "/api/business/products/" + id,
    method: "put",
    data: data,
  });
}

/**
 * 批量删除商品
 *
 * @param ids
 */
export function deletePro(ids: string) {
  return request({
    url: "/api/business/products/" + ids,
    method: "delete",
  });
}
